package com.diudiutechnology.www.yadiudiu.yadiudiu.main.MyAdapter;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.yadiudiu.model.BuyACarFragmentModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/31.
 */

public class HomePageListViewAdapter extends BaseAdapter {

    private Context mContext;
    List<BuyACarFragmentModel> model= new ArrayList<>();
    public HomePageListViewAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public int getCount() {
        if(model != null){
            return model.size() * 3;
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return model.get(position % model.size());
    }

    @Override
    public long getItemId(int position) {
        return position % model.size();
    }
    public void addItem( List<BuyACarFragmentModel> model){

        this.model=model;
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_home_page_listview, null);
            holder.congratulations = (TextView) convertView
                    .findViewById(R.id.congratulations);

            holder.number = (TextView) convertView
                    .findViewById(R.id.number);


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //holder.congratulations.setText(model.get(position % model.size()));//取余展示数据
        holder.congratulations.setText(Html.fromHtml("<font color='#FD1142'>恭喜</font>  重庆市"));
        holder.number.setText(Html.fromHtml("150****4321 抢得红包<font color='#FD1142'>2.00</font>元"));
        return convertView;
    }

    class ViewHolder {

        TextView congratulations;
        TextView number;

    }
}


